package com.jt.demos;

import redis.clients.jedis.Jedis;

import java.util.UUID;

public class SSODemo01 {
    /**
     * 单点登录应用实践
     * @param args
     */
    static String token;
    static void  doGetResource() {
        if(token==null){
            System.out.println("请先登录");
            return;
        }
        Jedis jedis = new Jedis("192.168.126.128",6379);
        String user = jedis.get(token);
        if (user==null) {
            System.out.println("登录超时");
            return;
        }
        System.out.println("登录成功");
    }
    static void doLogin(String username,String password){
        if ("jack".equals(username)&&"123456".equals(password)){
            String token = UUID.randomUUID().toString();
            Jedis jedis = new Jedis("192.168.126.128",6379);
            jedis.set(token, username);
            jedis.close();
            SSODemo01.token=token;
            return ;
        }

    }
    public static void main(String[] args) {
        //1访问资源
        doGetResource();
        //执行登录操作
        doLogin("jack","123456");
        //再次访问
        doGetResource();
    }
}
